import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        int n = scanner.nextInt();

        long[] arr = new long[n + 1];
        for (int i = 0; i < n; i++) {
            arr[i] = scanner.nextLong();
        }

        //创建前缀和数组
        long[] dp = new long[n + 1];

        //key为dp的元素%7的结果，value为该元素的最左边的下标
        HashMap<Long, Integer> map = new HashMap<>();
        map.put(0l, 0);

        int ret = Integer.MIN_VALUE;

        for (int i = 1; i < n + 1; i++) {
            dp[i] = dp[i - 1] + arr[i - 1];
            System.out.print(dp[i] + " ");
            int num = map.getOrDefault(dp[i] % 7, -1);
            if (num == -1) { //里面还没有这个元素
                map.put(dp[i] % 7, i); //添加元素
                continue;
            }
            ret = Math.max(ret, i - num);
        }

        System.out.println(ret == Integer.MIN_VALUE ? 0 : ret);

        scanner.close();
    }
}
